select-item <!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        body {
            padding: 0px 0px;
            margin: 0px 0px;
        }

        #type {
            width: 285px;
            height: 35px;
            background-color: rgba(106, 113, 121, 0.733);
            display: grid;
            grid-template-columns: repeat(2, 1fr);
            grid-template-rows: repeat(1, 1fr);
            grid-gap: 5px;
            padding: 0px 8px;
            position: absolute;
            top: 18px;
            left: 18px;
            border-radius: 5px;
            border: 2px solid rgba(164, 189, 218, 0.829);
        }

        .select-item {
            border-radius: 5px;
            margin: 5px 0px;
            text-align: center;
            user-select: none;
            background-color: rgb(145, 155, 151);
            border: 2px solid rgb(145, 155, 151);
        }

        .select-item-selected {
            background-color: rgba(49, 167, 100, 0.822);
        }

        .select-item:hover {
            border: 2px solid rgb(49, 167, 100);
        }

        #body-content {
            width: calc(100vw - 16px);
            height: calc(100vh - 16px);
            margin: 8px 8px;
            display: flex;
            align-content: center;
            justify-content: center;
            flex-wrap: wrap;
            background-color: #272626ef;
            border-radius: 5px;
            min-width: 650px;
            min-height: 600px;
        }

        .data-body-item {
            flex-direction: column;
        }

        .data-body-item>div {
            height: 35px;

            margin: 5px 0px;
        }

        input,
        label {
            height: 35px;
            margin-left: 5px;
            border-radius: 5px;
        }

        input {
            width: 280px;
            outline: 0px;
            border: 2px solid rgba(106, 155, 212, 0.904);
        }

        label {
            user-select: none;
            line-height: 35px;
            color: rgba(230, 230, 230, 0.856);
        }

        #operation-button {
            width: 120px;
            height: 35px;
            background-color: rgba(122, 121, 121, 0.87);
            position: absolute;
            bottom: 18px;
            right: 28px;
            border-radius: 5px;
            display: flex;
            align-items: center;
            justify-content: center;
            border: 2px solid rgba(164, 189, 218, 0.829);
            z-index: 2
        }

        #operation-button>button {
            width: 50px;
            height: 25px;
            border-radius: 5px;
            margin: 5px 5px;
            border: 0px;
        }

        #operation-button>button:active {
            background-color: rgba(49, 167, 100, 0.822);
        }

        .data-body-item>div {
            display: flex;
            width: 367px;
            justify-content: center;
        }

        #body-map {
            height: 300px;
            width: 650px;
            background-color: rgba(87, 110, 103, 0.616);
            overflow: visible;
        }

        svg {
            height: 35px;
            margin-right: 5px;
            width: 22px;

            border-radius: 5px;
        }

        #lib-item {
            width: 100%;
            display: flex;
            flex-wrap: wrap;
            justify-content: space-between;
            background-color: rgba(159, 238, 218, 0.144);
            margin-bottom: 2px;
            border-radius: 3px;
        }

        #lib-item>div {
            margin-left: 8px;
        }

        #lib-item>label {
            line-height: 42px;
            margin-left: 11px;
            width: 280px;
            height: 42px;
            text-overflow: ellipsis;
            overflow: hidden;
            white-space: nowrap;
        }

        #connect-button {
            width: 22px;
            padding: 3px 12px 0px 12px;
            background-color: rgba(119, 119, 119, 0.342);
            border-radius: 3px;
            margin: 0px 5px;
        }

        #connect-button:hover {
            background-color: rgba(134, 208, 226, 0.808);
        }

        ::-webkit-scrollbar {
            width: 6px;
            border-radius: 5px;
        }

        #content-map {
            width: calc(100vw - 18px);
            height: calc(100vh - 18px);
            z-index: 1;
            background-color: rgba(172, 180, 180, 0.733);
            position: absolute;
            top: 0px;
            left: 0px;
            margin: 9px 9px;
            display: none;
            justify-content: center;
            align-content: center;
            flex-wrap: wrap;
            flex-direction: column
        }

        #lib-name {
            width: 390px;
            height: 35px;
            background-color: rgb(143, 143, 143);
            text-align: center;
            line-height: 35px;
            border-radius: 5px;
        }

        #lib-map {
            height: 390px;
            width: 390px;
            background-color: rgb(139, 139, 139);
            margin-top: 5px;
            border-radius: 5px;
        }

        #manual-item {
            flex-wrap: wrap;
            display: flex;
            flex-direction: column;
            align-content: center;
        }

        #manual-item>div {
            display: flex;
            justify-content: space-between;
        }

        #library-map {
            display: grid;
            grid-template-columns: repeat(2, 1fr);
            grid-template-rows: repeat(1, 1fr);
            justify-content: space-between;
            flex-direction: column;
            height: 355px;
            width: 850px;

            margin-right: 3px;
        }

        #items-context {
            margin-left: 3px;
            border: 3px solid rgb(165, 165, 165);
        }

        #library-items {
            border: 3px solid rgb(165, 165, 165);
            overflow-y: auto;
            scrollbar-color: #888 #f1f1f1;
            scrollbar-width: thin;
            scrollbar-color: #888 #f1f1f1;
            overflow-x: hidden;
        }

        #library-items::-webkit-scrollbar {
            width: 2px;
            height: 0px;
            scrollbar-color: #888 #f1f1f1 !important;
        }

        #library-items::-webkit-scrollbar-track {
            background-color: #f1f1f191;

        }

        #library-items::-webkit-scrollbar-thumb {
            background-color: rgb(131, 131, 131);
        }

        #lib-item {
            margin: 6px 12px 0px 9px;
            width: 395px;
            scrollbar-width: none;
            scrollbar-color: #888 #f1f1f1;
        }
    </style>
</head>

<body>
    <div id="type">
        <div typeCode="package" class="select-item select-item-selected">war包/exploded</div>
        <div typeCode="manual" class="select-item">高级自定义</div>
    </div>

    <div id="body-content">
        <div class="data-body-item" id="package">
            <div style="color: rgb(255, 39, 1); height: 25px;margin-bottom: 39px;">
                建议每次启动tomcat时先编译项目，否则无法启动最新代码，并存在保存java文件时因签名不一致导致热加载失败等问题，
                建议使用高级配置
            </div>

            <div>
                <label>应用名:</label><input type="text" onblur="checkName(this)" placeholder="应用名/基础路径"> </input>
            </div>
            <div>
                <label>选择包:</label><input type="text" placeholder="war包/exploded"> </input>
            </div>
        </div>

        <div class="data-body-item" id="manual">
            <dev id="manual-item">
                <div style="margin-bottom: 8px; color: rgb(255, 39, 1)">
                    配置的目录使用软连接关联指向配置目录，后续更细自动同步
                </div>
                <div>
                    <label style="margin-left: 15px;">应用名</label><input type="text" placeholder="应用名/基础路径"> </input>
                </div>
                <div>
                    <label>WEB-INF</label><input type="text" placeholder="WEB-INF目录,建议绑定项目目录下的WEB-INF"> </input>
                </div>
                <div>
                    <label style="margin-left: 15px;">classes</label><input type="text"
                        placeholder="classes目录,建议绑定target/calsses"> </input>
                </div>
                <div>
                    <label style="margin-left: 35px;">lib</label><input type="text"
                        placeholder="指定lib目录,建议绑定target/lib">
                    </input>
                </div>
                <div style="margin-bottom: 8px; color: rgb(255, 39, 1)">
                    依赖库生成规则,服务器每次重启时会根据规则生成依赖库jar包
                </div>
            </dev>

            <div id="library-map">
                <div id="library-items"></div>
                <div id="items-context"></div>
            </div>

        </div>
    </div>


    <div id="operation-button">
        <button onclick="save()">保存</button>
        <button onclick="cancel(this)">取消</button>
    </div>
</body>
<script>
    var data = {
        type: "package"
    }

    function dataRender(){
        debugger
        if(data.type == "package"){
            if(data.name){
                document.querySelector("#package > div:nth-child(2) > input").value = data.name;
            }
            if(data.package){
                document.querySelector("#package > div:nth-child(3) > input").value = data.package;
            }
        }
    }
    const vscode = acquireVsCodeApi();

    function changeDevelopType(id) {
        // 取消选择标签
        let items = document.getElementsByClassName("select-item");
        for (let i = 0; i < items.length; i++) {
            items[i].classList.remove("select-item-selected");
        }

        // 页面切换
        items = document.getElementsByClassName('data-body-item');
        for (let i = 0; i < items.length; i++) {
            if (id == items[i].id) {
                items[i].style.display = "flex";
            } else {
                items[i].style.display = "none";
            }
        }

        // 选择当前选择标签
        data['type'] = id;
        if (id == 'manual') {
            let event = document.querySelector("#type > div:nth-child(2)");
            event.classList.add("select-item-selected");
            loadLibariry();
        } else {
            let event = document.querySelector("#type > div:nth-child(1)");
            event.classList.add("select-item-selected");
        }
    }

    // 库绑定
    function loadLibariry() {
        let items = document.getElementById("library-items");
        items.innerHTML = "";
        for (let i = 0; i < data.lib.length; i++) {
            let st = `style="color: green" title="配置绑定" `;
            let name = data.lib[i].name;
            items.innerHTML += `<div id="lib-item">
                <label title=${name}>${name}</label>
                    <div id="connect-button" onclick="setMap(this, '${name}')">
                        <svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-link" viewBox="0 0 16 16" ${data.lib[i].map && data.lib[i].map.length > 0 ? st : ""}>
                            <path d="M6.354 5.5H4a3 3 0 0 0 0 6h3a3 3 0 0 0 2.83-4H9q-.13 0-.25.031A2 2 0 0 1 7 10.5H4a2 2 0 1 1 0-4h1.535c.218-.376.495-.714.82-1z"/>
                            <path d="M9 5.5a3 3 0 0 0-2.83 4h1.098A2 2 0 0 1 9 6.5h3a2 2 0 1 1 0 4h-1.535a4 4 0 0 1-.82 1H12a3 3 0 1 0 0-6z"/>
                        </svg>
                    </div>
                </div>`;
        }
    }

    // 取消
    function cancel(event) {
        document.getElementById("content-map").style.display = "none";
    }

    function setMap(event, name) {
        console.log(name);
        console.log(event)
    }


    
    function checkName(event){
        data.name = event.value;
    }

    function save(){
        vscode.postMessage({ page: "develop.html", type: "save", data: data }, '*');
    }


    /** 事件处理 */
    function webviewReceive(message){
        message = message.data;
        switch(message.type){
            // 初始化
            case "init":{
                data = message.data ?? {
                    type: "package"
                };
                if(message.data != null && message.data != undefined){
                    document.getElementById("type").style.display = "none";
                    dataRender();
                }else{
                    document.getElementById("type").style.display = "grid";
                }
                changeDevelopType(data.type);
                
            }
        }
    }
    window.onload = () => {
        // 切换配置模式
        let items = document.getElementsByClassName("select-item");
        for (let i = 0; i < items.length; i++) {
            items[i].addEventListener("click", (event) => {
                data = {}
                changeDevelopType(event.target.getAttribute("typeCode"));

            })
        }
        // 默认模式
        changeDevelopType("package");
        window.addEventListener('message', webviewReceive);
        // 发送初始化请求
        vscode.postMessage({ page: "develop.html", type: "init" }, '*');
    }
    
</script>

</html>